package leetcode;

/**
 * Leetcode225【用队列实现栈】
 * https://leetcode-cn.com/problems/implement-stack-using-queues/
 */
import java.util.LinkedList;
import java.util.Queue;

public class QueueImplementStack {
    Queue<Integer> queue1 = new LinkedList<>();
    Queue<Integer> queue2 = new LinkedList<>();

    public QueueImplementStack() {

    }

    public void push(int x) {//入
        queue2.offer(x);
        while (!queue1.isEmpty()){
            queue2.offer(queue1.poll());
        }
        Queue<Integer> temp = queue1;
        queue1 = queue2;
        queue2 = temp;

    }

    public int pop() {//出删
        return queue1.poll();

    }

    public int top() {//不删
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}
